<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${path}/static/common/bootstrap-3.3.7-dist/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="${path}/static/common/layui/css/layui.css"/>
</head>
<body>
	<form id="form" class="layui-form layui-form-pane" action="">
	  <div class="layui-form-item">
	    <label class="layui-form-label">类别名称</label>
	    <div class="layui-input-block">
	      <input type="text" name="name" autocomplete="off" placeholder="请输入类别名称" class="layui-input">
	    </div>
	  </div>
	  </form>
	  <button class="layui-btn" onclick="submitForm()">添加</button>


	<script src="${path}/static/common/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
	<script src="${path}/static/common/layer/layer.js" type="text/javascript" charset="utf-8"></script>
	<script src="${path}/static/common/mylayer.js" type="text/javascript" charset="utf-8"></script>
	<script src="${path}/static/common/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	function submitForm() {
		$.post(
			"${path}/category/insert.action",
			$("#form").serialize(),
			function(result) {
				console.log(result);
				if(result.success) {
					mylayer.successMsg(result.msg);
					//当你在iframe页面关闭自身时获得当前弹出框的index索引
					var index = parent.layer.getFrameIndex(window.name);
					// js一个方法，定时器，1000毫秒之后自动执行function里面的代码
					setTimeout(function() {
						 // 关闭弹出层
						 parent.layer.close(index); 
						 // 刷新父页面
						 window.parent.location.reload();
					}, 1000);
				} else {
					mylayer.errorMsg(result.msg);
				}
			},
			"json"
		);
		
	}
	
	
	
	</script>
</body>
</html>